import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:lib_core/routes/boost_dialog_route.dart';
import 'package:lib_core/routes/common_routes.dart';

import '../lib_core.dart';
import 'boost_bottom_sheet.dart';

class CommonPages {
  CommonPages._();

  static final Map<String, FlutterBoostRouteFactory> commonPages = {
    CommonRoutes.bottomSheet: ((settings, uniqueId) {
      final arg = settings.arguments as Map<String, dynamic>?;
      Widget? bottomsheet = arg?['bottomsheet'];
      Color? backgroundColor = arg?['backgroundColor'];
      double? elevation = arg?['elevation'];
      bool persistent = arg?['persistent'] ?? true;
      ShapeBorder? shape = arg?['shape'];
      Clip? clipBehavior = arg?['clipBehavior'];
      Color? barrierColor = arg?['barrierColor'];
      bool? ignoreSafeArea = arg?['ignoreSafeArea'];
      bool? removeBottom = arg?['removeBottom'];
      bool isScrollControlled = arg?['isScrollControlled'] ?? false;
      bool useRootNavigator = arg?['useRootNavigator'] ?? false;
      bool isDismissible = arg?['isDismissible'] ?? true;
      bool enableDrag = arg?['enableDrag'] ?? true;
      // RouteSettings? mSettings = arg?['settings'];
      Duration? enterBottomSheetDuration = arg?['enterBottomSheetDuration'];
      Duration? exitBottomSheetDuration = arg?['exitBottomSheetDuration'];
      return BoostModalBottomSheetRoute(
        builder: (_) => bottomsheet ?? Container(),
        isPersistent: persistent,
        isScrollControlled: isScrollControlled,
        backgroundColor: backgroundColor ?? Colors.transparent,
        elevation: elevation,
        shape: shape,
        removeTop: ignoreSafeArea ?? true,
        removeBottom: removeBottom ?? false,
        clipBehavior: clipBehavior,
        isDismissible: isDismissible,
        modalBarrierColor: barrierColor,
        settings: settings,
        enableDrag: enableDrag,
        enterBottomSheetDuration: enterBottomSheetDuration ?? const Duration(milliseconds: 250),
        exitBottomSheetDuration: exitBottomSheetDuration ?? const Duration(milliseconds: 200),
      );
    }),
    CommonRoutes.dialog: ((settings, uniqueId) {
      final arg = settings.arguments as Map<String, dynamic>?;
      Widget widget = arg?['widget'] ?? Container();
      bool barrierDismissible = arg?['barrierDismissible'] ?? true;
      Color? barrierColor = arg?['barrierColor'];
      bool useSafeArea = arg?['useSafeArea'] ?? true;
      Duration? transitionDuration = arg?['transitionDuration'];
      Curve? transitionCurve = arg?['transitionCurve'];
      return BoostDialogRoute(
        pageBuilder: (buildContext, animation, secondaryAnimation) {
          final pageChild = widget;
          Widget dialog = Builder(builder: (context) {
            return Theme(data: Theme.of(context), child: pageChild);
          });
          if (useSafeArea) {
            dialog = SafeArea(child: dialog);
          }
          return dialog;
        },
        barrierDismissible: barrierDismissible,
        barrierColor: barrierColor ?? Colors.black54,
        transitionDuration: transitionDuration ?? const Duration(milliseconds: 300),
        transitionBuilder: (context, animation, secondaryAnimation, child) {
          return FadeTransition(
            opacity: CurvedAnimation(
              parent: animation,
              curve: transitionCurve ?? Curves.easeOutQuad,
            ),
            child: child,
          );
        },
        settings: settings,
      );
    }),
  };
}
